<?php
function delspace($str){   
	//space remove
	$str = trim($str); 
	$str = str_replace(" ","",$str);
	$str = preg_replace("/\s(?=\s)/", "", $str);
	return $str;
}

function is_english($str){ 
//check if it is Eng 
	return preg_match("/^[A-Za-z]+$/", $str); 
} 

function str_insert($str, $i, $substr) { 
	for($j=0; $j<$i; $j++){ 
		$startstr .= $str[$j]; 
	} 
	for ($j=$i; $j<strlen($str); $j++){ 
		$laststr .= $str[$j]; 
	} 
	$str = ($startstr . $substr . $laststr); 
	return $str; 
} 



function nameconvert($str){
//convert the first letter to uppercase
	if (is_english($str)){
		$str = strtolower($str);
		$str = ucfirst($str);
		return $str;
	}
	else	
		return $str;
}

function convertnum($str){
	$str = preg_replace('/[^\x7f-\xff\d]/', '', $str);
    return $str;
}



function is_num($str){ 
//check if it is num 
return preg_match("/^(-{0,1}|\+{0,1})[0-9]+(\.{0,1}[0-9]+)$/", $str); 
} 

$diglimited = "onkeyup=\"value=value.replace(/[^\d]/g,'')\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))\" ";

$dignspalimited = "onkeyup=\"value=value.replace(/[^\d\s]/g,'');this.value= checknumberformat(this.value)\" onbeforepaste=\"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\s]/g,''))\" ";

function formatMoney($number) { 
   $number = preg_replace('/(?<=\d)(?=(\d{3})+(?!\d))/', ',', $number);
   return $number; 
} 

function formatmonumber($num){
	$num = str_insert(delspace($num),4," "); 
	$num = str_insert($num,8," ");
	return $num;	
}

?>